package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Description：订单类
 * Copyright (c), 2024, lbs
 * This program is protected by copyright laws.
 * Date： 2024年09月26日
 *
 * @author 刘宝顺
 * @version : 1.0
 **/
public class Order  implements Comparable<Order>, Serializable {
    /**
     * 订单序号
     */
    private int no;

    /**
     * 总金额
     */
    private double totalPrice;

    /**
     * 状态
     */
    private String status;

    /**
     * 客户
     */
    private Customer customer;


    /**
     * 订单明细的容器
     */
    private List<OrderDetail> details;

    /**
     * 送餐时间
     */
    private String time;

    /**
     * 状态标志：0←正常；1←取消（订单被顾客取消）
     */
    private int flg;

    public Order() {
        //给属性details赋予初始值
        details = new ArrayList<>();
    }


    public Order(int no, double totalPrice, String status, Customer customer, List<OrderDetail> details, String time) {
        this.no = no;
        this.totalPrice = totalPrice;
        this.status = status;
        this.customer = customer;
        this.details = details;
        this.time = time;
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public List<OrderDetail> getDetails() {
        return details;
    }

    public void setDetails(List<OrderDetail> details) {
        this.details = details;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public int getFlg() {
        return flg;
    }

    public void setFlg(int flg) {
        this.flg = flg;
    }

    /**
     * 重写从父类中继承过来的toString方法
     *
     * @return 定制之后的当前类实例的字符串表现形式
     */
    @Override
    public String toString() {

        String no = String.valueOf(this.no);
        String customerName = this.customer.getName();

        String dishName = this.details.get(0).getDish().getName();
        String sendTime = this.time;
        String address = this.customer.getAddress();
        String totalMoney = String.format("%.2f", this.totalPrice);
        String orderStatus = this.status;


        String info = no + "\t\t"
                + customerName + "\t\t" + dishName + details.get(0).getCnt() + "份\t\t" + sendTime
                + "点\t\t" + address + "\t\t" + totalMoney + "元\t\t" + orderStatus
                + "\t\t" + flg;


        return info;
    }

    /**
     * 定制比较规则，哪个订单编号较大，那么，该实例也较大
     * @param o the object to be compared.
     * @return 数值 >0, =0,<0
     */
    @Override
    public int compareTo(Order o) {
        return o.no - this.no;
    }
}
